package cn.congzhou.crm.web.controller;

import cn.congzhou.crm.domain.Customer;
import cn.congzhou.crm.domain.SystemDictionary;
import cn.congzhou.crm.entity.MenuTree;
import cn.congzhou.crm.query.CustomerQueryObject;
import cn.congzhou.crm.query.QueryObject;
import cn.congzhou.crm.service.ICustomerService;
import cn.congzhou.crm.service.ISystemDictionaryService;
import com.alibaba.fastjson.JSON;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;

@Controller
public class IndexController {

    @Autowired
    private ICustomerService customerService;

    @Autowired
    private ISystemDictionaryService systemDictionaryService;

    @RequestMapping("/index")
    public String index(Model model){
        //组装字典目录菜单树
        List<SystemDictionary> systemDictionaries = systemDictionaryService.selectAll();
        List<MenuTree> children = new ArrayList<>();
        for (SystemDictionary systemDictionary : systemDictionaries) {
            MenuTree menuTree = new MenuTree();
            menuTree.setId(systemDictionary.getId());
            menuTree.setText(systemDictionary.getTitle());
            children.add(menuTree);
        }
        MenuTree menuTree = new MenuTree();
        menuTree.setText("字典明细");
        menuTree.setChildren(children);
        List<MenuTree> menuTrees = new ArrayList<>();
        menuTrees.add(menuTree);
        model.addAttribute("sysDictionary",JSON.toJSONString(menuTrees));
        return "/index";
    }

}
